package com.xiao;

import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import cn.hutool.http.Method;
import cn.hutool.json.JSONUtil;
import org.junit.jupiter.api.Test;

import javax.swing.plaf.PanelUI;
import java.util.HashMap;
import java.util.Map;

public class Demo01 {
    @Test
    public void testGet() {
        HashMap<String, Object> map = new HashMap<>();
        map.put("pageNum", 1);
        map.put("pageSize", 10);
        HttpResponse response = HttpUtil.createRequest(Method.GET, "http://localhost:9995/nursing_project").form(map).execute();
        System.out.println(response.body());
    }

    @Test
    public void testPost() {
        HashMap<String, Object> map = new HashMap<>();
        map.put("name", "aaa建材qqq");
        map.put("orderNo", 1);
        map.put("unit", 1);
        map.put("price", 100.00);
        map.put("image", 1);
        map.put("nursingRequirement", "没有");
        map.put("status", 1);
        HttpResponse execute = HttpUtil.createPost("http://localhost:9995/nursing_project").body(JSONUtil.toJsonStr(map)).execute();
        System.out.println(execute.body());
    }


    @Test
    public void get() {
        String host = "https://ali-weather.showapi.com";
        String path = "/area-to-weather-date";
        String method = "GET";
        String appcode = "0b6e5e9fd20446d0aa46b47d93b00117";
        Map<String, String> headers = new HashMap<String, String>();
        //最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
        headers.put("Authorization", "APPCODE " + appcode);
        Map<String, Object> querys = new HashMap<String, Object>();
        querys.put("areaCode", "530700");
        querys.put("area", "丽江");
        querys.put("date", "20200319");
        querys.put("need3HourForcast", "1");

        HttpResponse execute = HttpUtil.createGet(host + path).addHeaders(headers).form(querys).execute();
        System.out.println(execute.body());
    }

}